<template>
  <drag-dialog
    title="在线会商"
    :visible.sync="dialogVisible"
    :before-close="handleBeforeClose"
    left="unset"
    right="36px"
    top="80px"
    body-padding="24px 12px"
  >
    <div class="im-chat__contact">
      <div class="tabs">
        <div class="tab-item" :class="{ 'is-active': activeName === 'first' }" @click="onToggle('first')">通讯录</div>
        <div class="tab-item" :class="{ 'is-active': activeName === 'second' }" @click="onToggle('second')">消息</div>
      </div>

      <div class="search-box">
        <el-input v-model="searchKey" placeholder="请输入关键字搜索">
          <i slot="suffix" class="el-icon-search" @click="onSearch"></i>
        </el-input>
      </div>

      <div class="tab-pane">
        <el-scrollbar style="width: 100%; height: 100%;">
          <chat-address-book v-show="activeName === 'first'" :filter-text="searchKey"></chat-address-book>
          <chat-message-list v-show="activeName === 'second'"></chat-message-list>
        </el-scrollbar>
      </div>
    </div>
  </drag-dialog>
</template>

<script>
import chatAddressBook from './components/chat-address-book';
import chatMessageList from './components/chat-message-list';

export default {
  name: 'im-chat',
  components: { chatAddressBook, chatMessageList },
  props: {

  },
  data() {
    return {
      dialogVisible: true,
      activeName: 'second',
      searchKey: '',  // 搜索关键字
    };
  },
  methods: {
    handleBeforeClose(done) {
      done();
    },

    /**
     * tab 切换回调事件
     */
    onToggle(type) {
      this.activeName = type;
    },

    /**
     * 搜索
     */
    onSearch() {
      console.log('关键字: => ', this.searchKey);
    },
  },
};
</script>

<style lang="scss" scoped>
.im-chat__contact {
  width: 100%;
  height: 760px;

  .tabs {
    width: 100%;
    display: flex;
    margin-bottom: 10px;

    .tab-item {
      width: 50%;
      text-align: center;
      cursor: pointer;
      position: relative;
      font-size: 16px;
      color: #fff;
      padding-bottom: 6px;

      &::after {
        content: '';
        position: absolute;
        z-index: 1;
        bottom: -2px;
        height: 3px;
        width: 60%;
        left: 50%;
        transform: translateX(-50%);
        background-color: #04AFFF;
        opacity: 0;
        transition: all .3s;
      }

      &.is-active::after {
        opacity: 1;
      }
    }
  }

  .search-box {
    width: 100%;
    padding: 6px 0;

    ::v-deep .el-input {
      .el-input__inner {
        background-color: transparent;
        border-color: #00ACFC;
        caret-color: #00ACFC;
        color: #fff;
      }

      .el-input__suffix {
        width: 24px;
        display: inline-flex;
        align-items: center;
        cursor: pointer;
        color: #00ACFC;
      }
    }
  }

  .tab-pane {
    width: 100%;
    height: calc(100% - 82px);

    ::v-deep .el-scrollbar__wrap {
      overflow-x: hidden;
    }
  }
}
</style>
